{ config, lib, pkgs, ... }:

{
	imports =
		[
		./hardware-configuration.nix
		];

 boot.loader.systemd-boot = {
    enable = true;
    configurationLimit = 3; # <-- 设置你想保留的世代数量 (例如 3)
  };
	boot.loader.efi.canTouchEfiVariables = true;

	nixpkgs.config.allowUnfree = true;

	networking.hostName = "ifnk-pc"; # Define your hostname.
		time.timeZone = "Asia/Shanghai";
	virtualisation.vmware.guest.enable = true;

 # 2. 修改现有的 nix.settings 块，添加 Nix 守护进程的代理配置
  nix.settings = {
    experimental-features = [ "nix-command" "flakes" ]; # 保留你原来的设置
    substituters = [ "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" ]; # 保留你原来的设置
		sandbox = false; # 禁用沙盒(避免github 网络问题)
  };
	 nix.gc = {
    automatic = true;          # 启用自动垃圾回收
    dates = "daily";          # 设置运行频率 (例如 "daily", "weekly", "monthly", 或具体时间 "02:00")
    options = "--delete-older-than 1d"; # <-- 删除超过 7 天的旧世代引用的包
                                         # 注意：这不直接删除世代本身，而是清理它们引用的不再需要的包
                                         # 结合上面的 configurationLimit 更有效
  };

 # ++ 添加国际化和本地化设置 ++
  i18n.defaultLocale = "zh_CN.UTF-8";
  i18n.extraLocaleSettings = {
    LC_ADDRESS = "zh_CN.UTF-8";
    LC_IDENTIFICATION = "zh_CN.UTF-8";
    LC_MEASUREMENT = "zh_CN.UTF-8";
    LC_MONETARY = "zh_CN.UTF-8";
    LC_NAME = "zh_CN.UTF-8";
    LC_NUMERIC = "zh_CN.UTF-8";
    LC_PAPER = "zh_CN.UTF-8";
    LC_TELEPHONE = "zh_CN.UTF-8";
    LC_TIME = "zh_CN.UTF-8"; # 你也可以根据需要保留英文时间格式，例如设置为 en_US.UTF-8
  };

  # 输入法设置
  i18n.inputMethod = {
    enabled = "fcitx5";
  };


  # 环境变量设置
  environment.variables = {
    http_proxy = "http://192.168.1.235:7890";
    https_proxy = "http://192.168.1.235:7890";
    ftp_proxy = "http://192.168.1.235:7890";
    all_proxy = "http://192.168.1.235:7890";
    no_proxy = "localhost,127.0.0.1,192.168.0.0/16,.local";

    HTTP_PROXY = "http://192.168.1.235:7890";
    HTTPS_PROXY = "http://192.168.1.235:7890";
    FTP_PROXY = "http://192.168.1.235:7890";
    ALL_PROXY = "http://192.168.1.235:7890";
    NO_PROXY = "localhost,127.0.0.1,192.168.0.0/16,.local";

    EDITOR = "vim";
    
    # 输入法环境变量
    GTK_IM_MODULE = "fcitx";
    QT_IM_MODULE = "fcitx";
    XMODIFIERS = "@im=fcitx";
    SDL_IM_MODULE = "fcitx";
    GLFW_IM_MODULE = "ibus";
  };

	#security.sudo.wheelNeedsPassword = false;
		users.users.ifnk= { #用户名是yh
			isNormalUser = true;
			password = "ifnk";
			extraGroups = [
				"wheel"
					"users"
			];
		};

	environment.systemPackages = with pkgs; [
		git
		wget
		curl
		unzip
		vim
		neofetch
		rofi
		feh
		xfce.thunar
		lxappearance
		imagemagick
	];

	services.openssh.enable = true;


	system.stateVersion = "25.05";

  # 3. 【重要】为 Nix 守护进程服务设置代理环境变量
  systemd.services.nix-daemon.environment = {
    HTTP_PROXY = "http://192.168.1.235:7890";
    HTTPS_PROXY = "http://192.168.1.235:7890";
    FTP_PROXY = "http://192.168.1.235:7890"; # 虽然少见，但加上无妨
    NO_PROXY = "localhost,127.0.0.1,192.168.0.0/16,.local"; # Nix 守护进程也需要知道哪些不走代理
  };


	services.xserver = {
		enable = true;
    videoDrivers = [ "vmware" ]; # 确保有这行

		
		desktopManager = {
			xterm.enable = false;
		};
		
		displayManager = {
			defaultSession = "none+i3";
		};
		
		windowManager.i3 = {
			enable = true;
			package = pkgs.i3-gaps;
			extraPackages = with pkgs; [
				dmenu
				i3status
				i3lock
				i3blocks
				rofi
				feh
				alacritty
				xfce.thunar
			];
		};

	};


	# 添加备份设置，防止文件冲突
	home-manager.backupFileExtension = "bak";
}
